<!--
 * 系统首页
 *
 * @Author: ShanZhu
 * @Date: 2023-12-03
-->
<template>
  <div class="scifi-home-container">
    <!-- 动态背景元素 -->
    <div class="scifi-bg-elements">
      <div class="floating-orb orb-1"></div>
      <div class="floating-orb orb-2"></div>
      <div class="floating-orb orb-3"></div>
      <div class="grid-lines"></div>
    </div>

    <!-- 内容区域 -->
    <div class="scifi-content-wrapper">
      <!-- 面包屑导航 -->
      <div class="scifi-breadcrumb">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item>
            <i class="iconfont icon-home-menu" style="margin: 5px; font-size: 22px">
              首页
            </i>
          </el-breadcrumb-item>
        </el-breadcrumb>
      </div>

      <!-- 主内容区域 -->
      <div class="scifi-main-content">
        <div class="scifi-welcome-section">
          <h1 class="scifi-welcome-title">欢迎访问慧停车</h1>
          <p class="scifi-welcome-subtitle">智能停车 · 科技未来</p>
        </div>

        <!-- 轮播图区域 -->
        <div class="scifi-carousel-section">
          <div class="scifi-carousel-container">
            <div class="scifi-carousel" @mouseenter="pauseAutoPlay" @mouseleave="startAutoPlay">
              <!-- 轮播轨道 -->
              <div
                  class="carousel-track"
                  :style="{ transform: `translateX(-${currentIndex * 100}%)` }"
              >
                <div
                    v-for="(image, index) in carouselImages"
                    :key="index"
                    class="carousel-slide"
                >
                  <img
                      :src="require(`@/assets/img/${image.src}`)"
                      :alt="image.alt"
                      class="carousel-image"
                  >
                  <div class="image-glow"></div>
                  <div class="carousel-caption">
                    <h3>{{ image.title }}</h3>
                    <p>{{ image.description }}</p>
                  </div>
                </div>
              </div>

              <!-- 导航按钮 -->
              <button class="carousel-btn carousel-prev" @click="prevSlide">
                <i class="el-icon-arrow-left"></i>
              </button>
              <button class="carousel-btn carousel-next" @click="nextSlide">
                <i class="el-icon-arrow-right"></i>
              </button>

              <!-- 指示器 -->
              <div class="carousel-indicators">
                <button
                    v-for="(_, index) in carouselImages"
                    :key="index"
                    class="indicator"
                    :class="{ active: currentIndex === index }"
                    @click="goToSlide(index)"
                ></button>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 公告列表 -->
      <NoticeList v-if="isCommonUser && userInfoLoaded" ref="noticeList"></NoticeList>
    </div>
  </div>
</template>

<script>
import NoticeList from './person/NoticeList.vue';
import axios from "axios";

export default {
  components: {
    NoticeList
  },
  data() {
    return {
      isCommonUser: false,
      userInfoLoaded: false,
      currentIndex: 0,
      autoPlayInterval: null,
      carouselImages: [
        {
          src: '03.jpg',
          alt: '现代化停车场',
          title: '现代化停车场',
          description: '智能化的停车设施，为您提供便捷的停车体验'
        },
        {
          src: '01.jpg',
          alt: '智能停车系统',
          title: '智能停车系统',
          description: '先进的停车管理系统，实时监控车位状态'
        },
        {
          src: '02.jpg',
          alt: '科技未来停车',
          title: '科技未来停车',
          description: '融合科技与创新的未来停车解决方案'
        }
      ]
    };
  },
  methods: {
    // 检查是否为普通用户
    checkUserType() {
      try {
        const userInfoStr = window.sessionStorage.getItem("userInfo");
        if (userInfoStr) {
          const userInfo = JSON.parse(userInfoStr);
          this.isCommonUser = userInfo.username !== 'admin';
          this.userInfoLoaded = true;
        } else {
          const uid = window.sessionStorage.getItem("token");
          if (uid) {
            axios.get("/api/user/getUserByUid?uid=" + uid).then((res) => {
              window.sessionStorage.setItem("userInfo", JSON.stringify(res.data.data));
              this.isCommonUser = res.data.data.username !== 'admin';
              this.userInfoLoaded = true;
            }).catch((error) => {
              console.error("获取用户信息失败", error);
              this.isCommonUser = true;
              this.userInfoLoaded = true;
            });
          } else {
            this.isCommonUser = true;
            this.userInfoLoaded = true;
          }
        }
      } catch (e) {
        console.error("解析用户信息失败", e);
        this.isCommonUser = true;
        this.userInfoLoaded = true;
      }
    },

    // 轮播图方法
    nextSlide() {
      this.currentIndex = (this.currentIndex + 1) % this.carouselImages.length;
    },

    prevSlide() {
      this.currentIndex = this.currentIndex === 0
          ? this.carouselImages.length - 1
          : this.currentIndex - 1;
    },

    goToSlide(index) {
      this.currentIndex = index;
    },

    startAutoPlay() {
      this.autoPlayInterval = setInterval(() => {
        this.nextSlide();
      }, 4000);
    },

    pauseAutoPlay() {
      if (this.autoPlayInterval) {
        clearInterval(this.autoPlayInterval);
        this.autoPlayInterval = null;
      }
    }
  },

  mounted() {
    this.checkUserType();
    this.startAutoPlay();
  },

  beforeDestroy() {
    this.pauseAutoPlay();
  }
};
</script>

<style lang="less" scoped>
@import 'styles/Login.less';

.scifi-home-container {
  position: relative;
  min-height: 100vh;
  background: linear-gradient(135deg, #0c0c2e 0%, #1a1a3e 50%, #2d2d5e 100%);
  color: #fff;
  font-family: 'Arial', sans-serif;
  overflow-x: hidden;
}

.scifi-content-wrapper {
  position: relative;
  z-index: 2;
  padding: 20px;
}

.scifi-breadcrumb {
  margin-bottom: 20px;

  :deep(.el-breadcrumb) {
    color: rgba(255, 255, 255, 0.7);

    .el-breadcrumb__inner {
      color: #00ffff;

      i {
        color: #00ffff;
        text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
      }
    }

    .el-breadcrumb__separator {
      color: rgba(0, 255, 255, 0.5);
    }
  }
}

.scifi-main-content {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 40px;
  margin-top: 20px;
  box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.2),
      0 0 20px rgba(0, 255, 255, 0.1);
  animation: glow 2s ease-in-out infinite alternate;
}

.scifi-welcome-section {
  text-align: center;
  margin-bottom: 40px;
}

.scifi-welcome-title {
  color: #00ffff;
  font-size: 36px;
  font-weight: 300;
  margin-bottom: 10px;
  text-shadow: 0 0 15px rgba(0, 255, 255, 0.7);
  letter-spacing: 2px;
}

.scifi-welcome-subtitle {
  color: rgba(255, 255, 255, 0.8);
  font-size: 18px;
  margin: 0;
  font-weight: 300;
}

/* 轮播图样式 */
.scifi-carousel-section {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 30px;
}

.scifi-carousel-container {
  width: 100%;
  max-width: 900px;
  position: relative;
}

.scifi-carousel {
  position: relative;
  width: 100%;
  height: 500px;
  border-radius: 20px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 255, 255, 0.2);
  box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.1),
      0 0 30px rgba(0, 255, 255, 0.2);
}

/* 轮播轨道 */
.carousel-track {
  display: flex;
  transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  height: 100%;
}

/* 轮播项 */
.carousel-slide {
  position: relative;
  min-width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.carousel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.8);
  transition: transform 0.6s ease;
}

.carousel-slide:hover .carousel-image {
  transform: scale(1.05);
}

/* 图片光效 */
.image-glow {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
      45deg,
      transparent 0%,
      rgba(0, 255, 255, 0.1) 50%,
      transparent 100%
  );
  animation: glowMove 3s ease-in-out infinite;
}

@keyframes glowMove {
  0%, 100% {
    transform: translateX(-100%);
  }
  50% {
    transform: translateX(100%);
  }
}

/* 图片标题 */
.carousel-caption {
  position: absolute;
  bottom: 40px;
  left: 40px;
  right: 40px;
  text-align: left;
  z-index: 2;
}

.carousel-caption h3 {
  color: #00ffff;
  font-size: 2rem;
  font-weight: 300;
  margin-bottom: 10px;
  text-shadow: 0 0 15px rgba(0, 255, 255, 0.7);
  letter-spacing: 1px;
}

.carousel-caption p {
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.1rem;
  margin: 0;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

/* 导航按钮 */
.carousel-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  color: #00ffff;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-btn:hover {
  background: rgba(0, 255, 255, 0.4);
  box-shadow: 0 0 20px rgba(0, 255, 255, 0.6);
  transform: translateY(-50%) scale(1.1);
}

.carousel-prev {
  left: 20px;
}

.carousel-next {
  right: 20px;
}

/* 指示器 */
.carousel-indicators {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 3;
}

.indicator {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.indicator::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
  transition: left 0.5s ease;
}

.indicator:hover::before {
  left: 100%;
}

.indicator.active {
  background: #00ffff;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.8);
  transform: scale(1.2);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .scifi-content-wrapper {
    padding: 10px;
  }

  .scifi-main-content {
    padding: 20px;
  }

  .scifi-welcome-title {
    font-size: 24px;
  }

  .scifi-welcome-subtitle {
    font-size: 14px;
  }

  .scifi-carousel {
    height: 400px;
  }

  .carousel-caption {
    bottom: 20px;
    left: 20px;
    right: 20px;
  }

  .carousel-caption h3 {
    font-size: 1.5rem;
  }

  .carousel-caption p {
    font-size: 0.9rem;
  }

  .carousel-btn {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .scifi-carousel {
    height: 300px;
  }

  .carousel-caption h3 {
    font-size: 1.2rem;
  }

  .carousel-caption p {
    font-size: 0.8rem;
  }

  .carousel-indicators {
    bottom: 10px;
  }

  .indicator {
    width: 8px;
    height: 8px;
  }
}
</style>